package com.android;

class aStarSolve {
    private String tmp;
    String arry [][] = new String [4][4];
    private int cAstar;
    int cn[] = new int [16];
    int g;
    protected void aStarSolve( String  strArr[][]){
        for(int i = 0; i <= 3; i++){
    		for(int j = 0; j <= 3; j++){
    			arry[i][j] = strArr[i][j];
    		}
    	}
    }
    protected void setContvalue(int cntA[]){//tesss
    	for(int i = 0; i <= 15; i++){
    		cn[i] = cntA[i];
   		
    	}
    }
    protected void setValueAstar( int num){
         this.cAstar = num;  // set value for integer [count]
    }
    protected int getValarry(int i, int j){
    	//Integer.parseInt( arry[i][j] );
    	g  = Integer.parseInt( arry[i][j] );
    	return g -1;
    }
    protected void aStarCheck(){
		if( arry[0][0].equals(" ") )        solveBox1(); //btn1 is free space call solveBox1()
		else if ( arry[0][1].equals(" ") )  solveBox2();
		else if ( arry[0][2].equals(" ") )  solveBox3();
		else if ( arry[0][3].equals(" ") )  solveBox4();
		else if ( arry[1][0].equals(" ") )  solveBox5();
		else if ( arry[1][1].equals(" ") )  solveBox6();
		else if ( arry[1][2].equals(" ") )  solveBox7();
		else if ( arry[1][3].equals(" ") )  solveBox8();
		else if ( arry[2][0].equals(" ") )  solveBox9();
		else if ( arry[2][1].equals(" ") )  solveBox10();
		else if ( arry[2][2].equals(" ") )  solveBox11();
		else if ( arry[2][3].equals(" ") )  solveBox12();
		else if ( arry[3][0].equals(" ") )  solveBox13();
		else if ( arry[3][1].equals(" ") )  solveBox14();
		else if ( arry[3][2].equals(" ") )  solveBox15();
		else if ( arry[3][3].equals(" ") && (chkHeu() != 0)) solveBox16();
	}

    private void swap( int a, int b ,int c , int d ){
        tmp   = arry[a][b];
        arry[a][b] = arry[c][d];
        arry[c][d] = tmp;
	}

    private void normalState( int a, int b ,int c , int d ){
        arry[c][d] = arry[a][b];
        arry[a][b] = tmp;
	}
    public int heruetic[] = new int [8];
    public int h[] = new int [16];
	private void solveBox1() {
       if(arry[0][0].equals(" ") ){
           // swap box1 <-> box5
    	   swap(0,0, 1,0);	   
           heruetic[0] = chkHeu() + cn[getValarry(0,0)];
           heruetic[4] = herue;
           //set to normal state  1 <=> 5
           normalState(0,0, 1,0);

           // swap box1 <-> box2
           swap(0,0, 0,1);
           heruetic[1] = chkHeu() + cn[getValarry(0,0)];
           heruetic[5] = herue;
           //set to normal state  1 <=> 2
           normalState(0,0, 0,1);

           



           if(heruetic[0] <= heruetic[1]){
              // swap box1 <-> box5
        	   swap(0,0, 1,0);
        	   cn[getValarry(0,0)]++;
           }else if(heruetic[0] > heruetic[1]){
               // swap box1 <-> box2
              swap(0,0, 0,1);
              cn[getValarry(0,0)]++;
           }

       }
	}
	private void solveBox2() {
     
       if(arry[0][1].equals(" ") ){
           // swap box2 <-> box1
    	   swap(0,1, 0,0);
           heruetic[0] = chkHeu() + cn[getValarry(0,1)];
           heruetic[4] = herue;
           //set to normal state  2 <=> 1
           normalState(0,1, 0,0);

           // swap box2 <-> box3
           swap(0,1, 0,2);
           heruetic[1] = chkHeu() + cn[getValarry(0,1)];
           heruetic[5] = herue;
           //set to normal state  2 <=> 3
           normalState(0,1, 0,2);

           // swap box2 <-> box6
           swap(0,1, 1,1);
           heruetic[2] = chkHeu() + cn[getValarry(0,1)];
           heruetic[6] = herue;
           //set to normal state  2 <=> 6
           normalState(0,1, 1,1);

           if(heruetic[0] <= heruetic[1]){
               if(heruetic[0] <= heruetic[2]){
                  swap(0,1, 0,0);
                  cn[getValarry(0,1)]++;
               }
               else{
                  swap(0,1, 1,1);
                  cn[getValarry(0,1)]++;
               }
           }else{
              if(heruetic[1] <= heruetic[2]){
                  swap(0,1, 0,2);
                  cn[getValarry(0,1)]++;
              }
              else{
                  swap(0,1, 1,1);
                  cn[getValarry(0,1)]++;
              }
           }

       }
	}
	private void solveBox3() {
       
      if(arry[0][2].equals(" ") ){
    	// swap box3 <-> box2
          swap(0,2, 0,1);
          heruetic[0] = chkHeu() + cn[getValarry(0,2)];
          heruetic[4] = herue;
          //set to normal state  3 <=> 2
          normalState(0,2, 0,1);

          // swap box3 <-> box4
          swap(0,2, 0,3);
          heruetic[1] = chkHeu() + cn[getValarry(0,2)];
          heruetic[5] = herue;
          //set to normal state  3 <=> 4
          normalState(0,2, 0,3);

          // swap box3 <-> box7
          swap(0,2, 1,2);
          heruetic[2] = chkHeu() + cn[getValarry(0,2)];
          heruetic[6] = herue;
          //set to normal state  3 <=> 7
          normalState(0,2, 1,2);

          if(heruetic[0] <= heruetic[1]){
              if(heruetic[0] <= heruetic[2]){
                 swap(0,2, 0,1);
                 cn[getValarry(0,2)]++;
              }
              else{
                 swap(0,2, 1,2);
                 cn[getValarry(0,2)]++;
              }
          }else{
             if(heruetic[1] <= heruetic[2]){
                 swap(0,2, 0,3);
                 cn[getValarry(0,2)]++;
             }
             else{
                 swap(0,2, 1,2);
                 cn[getValarry(0,2)]++;

             }
          }
       }
	}
	private void solveBox4() {
       
       if(arry[0][3].equals(" ") ){
    	// swap box4 <-> box3
           swap(0,3, 0,2);
           heruetic[0] = chkHeu() + cn[getValarry(0,3)];
           heruetic[4] = herue;
           //set to normal state  4 <=> 3
           normalState(0,3, 0,2);

           // swap box4 <-> box8
           swap(0,3, 1,3);
           heruetic[1] = chkHeu() + cn[getValarry(0,3)];
           heruetic[5] = herue;
           //set to normal state  4 <=> 8
           normalState(0,3, 1,3);


           if(heruetic[0] <= heruetic[1]){
               // swap box4 <-> box3
               swap(0,3, 0,2);
               cn[getValarry(0,3)]++;
            }else if(heruetic[0] > heruetic[1]){
                // swap box4 <-> box8
               swap(0,3, 1,3);
               cn[getValarry(0,3)]++;
            }
       }
	}
	private void solveBox5() {
     
       if(arry[1][0].equals(" ") ){  // value in box is 5
    	   // swap box5 <-> box1
           swap(1,0, 0,0);
           heruetic[0] = chkHeu() + cn[getValarry(1,0)];
           heruetic[4] = herue;
           //set to normal state  5 <=> 1
           normalState(1,0, 0,0);

           // swap box5 <-> box6
           swap(1,0, 1,1);
           heruetic[1] = chkHeu() + cn[getValarry(1,0)];
           heruetic[5] = herue;
           //set to normal state  5 <=> 6
           normalState(1,0, 1,1);

           // swap box5 <-> box9
           swap(1,0, 2,0);
           heruetic[2] = chkHeu() + cn[getValarry(1,0)];
           heruetic[6] = herue;
           //set to normal state  5 <=> 9
           normalState(1,0, 2,0);


           if(heruetic[0] <= heruetic[1]){
               if(heruetic[0] <= heruetic[2]){
                  swap(1,0, 0,0);
                  cn[getValarry(1,0)]++;
               }
               else{
                  swap(1,0, 2,0);
                  cn[getValarry(1,0)]++;
               }
           }else{
              if(heruetic[1] <= heruetic[2]){
                  swap(1,0, 1,1);
                  cn[getValarry(1,0)]++;
              }
              else{
            	  swap(1,0, 2,0);
            	  cn[getValarry(1,0)]++;
              }
           }
       }
	}
	private void solveBox6() {
      
       if(arry[1][1].equals(" ") ){  // value in box is 6
    	// swap box6 <-> box5
           swap(1,1, 1,0);
           heruetic[0] = chkHeu() + cn[getValarry(1,1)];
           heruetic[4] = herue;
           //set to normal state  6 <=> 5
           normalState(1,1, 1,0);

           // swap box6 <-> box2
           swap(1,1, 0,1);
           heruetic[1] = chkHeu() + cn[getValarry(1,1)];
           heruetic[5] = herue;
           //set to normal state  6 <=> 2
           normalState(1,1, 0,1);

           // swap box6 <-> box7
           swap(1,1, 1,2);
           heruetic[2] = chkHeu() + cn[getValarry(1,1)];
           heruetic[6] = herue;
           //set to normal state  6 <=> 7
           normalState(1,1, 1,2);

           // swap box6 <-> box10
           swap(1,1, 2,1);
           heruetic[3] = chkHeu() + cn[getValarry(1,1)];
           heruetic[7] = herue;
           //set to normal state  6 <=> 10
           normalState(1,1, 2,1);


           if(heruetic[0] <= heruetic[1]){ // YYY big
               if(heruetic[0] <= heruetic[2]){ // xxx1
                   if(heruetic[0] <= heruetic[3]){
                            swap(1,1, 1,0);
                            cn[getValarry(1,1)]++;
                   }else{
                            swap(1,1, 2,1);
                            cn[getValarry(1,1)]++;
                   }
               }
               else{ // xxx1
                   if(heruetic[2] <= heruetic[3]){
                            swap(1,1, 1,2);
                            cn[getValarry(1,1)]++;
                   }else{
                            swap(1,1, 2,1);
                            cn[getValarry(1,1)]++;
                   }
               }
           }else{ // YYY big
               if(heruetic[1] <= heruetic[2]){ // xxx2
                   if(heruetic[1] <= heruetic[3]){
                            swap(1,1, 0,1);
                            cn[getValarry(1,1)]++;
                   }else{
                            swap(1,1, 2,1);
                            cn[getValarry(1,1)]++;
                   }
               }
               else{ // xxx2
                    if(heruetic[2] <= heruetic[3]){
                            swap(1,1, 1,2);
                            cn[getValarry(1,1)]++;
                   }else{
                            swap(1,1, 2,1);
                            cn[getValarry(1,1)]++;
                   }
               }
           }

           
       }
	}
	private void solveBox7() {
       
      if(arry[1][2].equals(" ") ){  // value in box is 7
    	  // swap box7 <-> box6
          swap(1,2, 1,1);
          heruetic[0] = chkHeu() + cn[getValarry(1,2)];
          heruetic[4] = herue;
          //set to normal state  7 <=> 6
          normalState(1,2, 1,1);

          // swap box7 <-> box3
          swap(1,2, 0,2);
          heruetic[1] = chkHeu() + cn[getValarry(1,2)];
          heruetic[5] = herue;
          //set to normal state  7 <=> 3
          normalState(1,2, 0,2);

          // swap box7 <-> box8
          swap(1,2, 1,3);
          heruetic[2] = chkHeu() + cn[getValarry(1,2)];
          heruetic[6] = herue;
          //set to normal state  7 <=> 8
          normalState(1,2, 1,3);

          // swap box7 <-> box11
          swap(1,2, 2,2);
          heruetic[3] = chkHeu() + cn[getValarry(1,2)];
          heruetic[7] = herue;
          //set to normal state  7 <=> 11
          normalState(1,2, 2,2);



          if(heruetic[0] <= heruetic[1]){ // YYY big
              if(heruetic[0] <= heruetic[2]){ // xxx1
                  if(heruetic[0] <= heruetic[3]){
                           swap(1,2, 1,1);
                           cn[getValarry(1,2)]++;
                  }else{
                           swap(1,2, 2,2);
                           cn[getValarry(1,2)]++;
                  }
              }
              else{ // xxx1
                  if(heruetic[2] <= heruetic[3]){
                           swap(1,2, 1,3);
                           cn[getValarry(1,2)]++;
                  }else{
                           swap(1,2, 2,2);
                           cn[getValarry(1,2)]++;
                  }
              }
          }else{ // YYY big
              if(heruetic[1] <= heruetic[2]){ // xxx2
                  if(heruetic[1] <= heruetic[3]){
                           swap(1,2, 0,2);
                           cn[getValarry(1,2)]++;
                  }else{
                           swap(1,2, 2,2);
                           cn[getValarry(1,2)]++;
                  }
              }
              else{ // xxx2
                   if(heruetic[2] <= heruetic[3]){
                           swap(1,2, 1,3);
                           cn[getValarry(1,2)]++;
                  }else{
                           swap(1,2, 2,2);
                           cn[getValarry(1,2)]++;
                  }
              }
          }
      }
	}
	private void solveBox8() {
       
       if(arry[1][3].equals(" ") ){  // value in box is 8
    	   // swap box8 <-> box7
           swap(1,3, 1,2);
           heruetic[0] = chkHeu() + cn[getValarry(1,3)];
           heruetic[4] = herue;
           //set to normal state  8 <=> 7
           normalState(1,3, 1,2);

           // swap box8 <-> box4
           swap(1,3, 0,3);
           heruetic[1] = chkHeu() + cn[getValarry(1,3)];
           heruetic[5] = herue;
           //set to normal state  8 <=> 4
           normalState(1,3, 0,3);

           // swap box8 <-> box12
           swap(1,3, 2,3);
           heruetic[2] = chkHeu() + cn[getValarry(1,3)];
           heruetic[6] = herue;
           //set to normal state  8 <=> 12
           normalState(1,3, 2,3);

           if(heruetic[0] <= heruetic[1]){
               if(heruetic[0] <= heruetic[2]){
                  swap(1,3, 1,2);
                  cn[getValarry(1,3)]++;
               }
               else{
                  swap(1,3, 2,3);
                  cn[getValarry(1,3)]++;
               }
           }else{
              if(heruetic[1] <= heruetic[2]){
                  swap(1,3, 0,3);
                  cn[getValarry(1,3)]++;
              }
              else{
                  swap(1,3, 2,3);
                  cn[getValarry(1,3)]++;

              }
           }
       }
       }
	
	private void solveBox9() {
       
	       if(arry[2][0].equals(" ") ){
	    	// swap box9 <-> box5
	           swap(2,0, 1,0);
	           heruetic[0] = chkHeu() + cn[getValarry(2,0)];
	           heruetic[4] = herue;
	           //set to normal state  9 <=> 5
	           normalState(2,0, 1,0);

	           // swap box9 <-> box10
	           swap(2,0, 2,1);
	           heruetic[1] = chkHeu() + cn[getValarry(2,0)];
	           heruetic[5] = herue;
	           //set to normal state  9 <=> 10
	           normalState(2,0, 2,1);

	           // swap box9 <-> box13
	           swap(2,0, 3,0);
	           heruetic[2] = chkHeu() + cn[getValarry(2,0)];
	           heruetic[6] = herue;
	           //set to normal state  9 <=> 13
	           normalState(2,0, 3,0);
	           
	           if(heruetic[0] <= heruetic[1]){
	        	   if(heruetic[0] <= heruetic[2]){
	        		   swap(2,0, 1,0);
	        		   cn[getValarry(2,0)]++;
	        	   }
	        	   else{
	        		   swap(2,0, 3,0);
	        		   cn[getValarry(2,0)]++;
	        	   }
	           	}else{
	        	   if(heruetic[1] <= heruetic[2]){
	        		   swap(2,0, 2,1);
	        		   cn[getValarry(2,0)]++;
	        	   }
	        	   else{
	        		   swap(2,0, 3,0);
	        		   cn[getValarry(2,0)]++;
	        	   }
	           	}
	  }
	}
	private void solveBox10() {
       
	       if(arry[2][1].equals(" ") ){
	    	   // swap box10 <-> box9
	           swap(2,1, 2,0);
	           heruetic[0] = chkHeu() + cn[getValarry(2,1)];
	           heruetic[4] = herue;
	           //set to normal state  10 <=> 9
	           normalState(2,1, 2,0);

	           // swap box10 <-> box6
	           swap(2,1, 1,1);
	           heruetic[1] = chkHeu() + cn[getValarry(2,1)];
	           heruetic[5] = herue;
	           //set to normal state  10 <=> 6
	           normalState(2,1, 1,1);

	           // swap box10 <-> box11
	           swap(2,1, 2,2);
	           heruetic[2] = chkHeu() + cn[getValarry(2,1)];
	           heruetic[6] = herue;
	           //set to normal state  10 <=> 11
	           normalState(2,1, 2,2);

	           // swap box10 <-> box14
	           swap(2,1, 3,1);
	           heruetic[3] = chkHeu() + cn[getValarry(2,1)];
	           heruetic[7] = herue;
	           //set to normal state  10 <=> 14
	           normalState(2,1, 3,1);
	           
	           if(heruetic[0] <= heruetic[1]){//xxxx big
	        	   if(heruetic[0] <= heruetic[2]){//xxx
	        		   if(heruetic[0] <= heruetic[3]){
	        			   swap(2,1, 2,0);
	        				cn[getValarry(2,1)]++;
		        	   }
		        	   else{
		        		   swap(2,1, 3,1);
		        			cn[getValarry(2,1)]++;
		        	   }

	        	   }
	        	   else{//xxx
	        		   if(heruetic[2] <= heruetic[3]){
		        		   swap(2,1, 2,2);
		        			cn[getValarry(2,1)]++;
		        	   }
		        	   else{
		        		   swap(2,1, 3,1);
		        			cn[getValarry(2,1)]++;
		        	   }
	        	   }
	           }else{//xxxx big
	        	   if(heruetic[1] <= heruetic[2]){
	        		   if(heruetic[1] <= heruetic[3]){
		        		   swap(2,1, 1,1);
		        			cn[getValarry(2,1)]++;
		        	   }
		        	   else{
		        		   swap(2,1, 3,1);
		        			cn[getValarry(2,1)]++;
		        	   }
	        	   }
	        	   else{
	        		   if(heruetic[2] <= heruetic[3]){
	        			   swap(2,1, 2,2);
	        				cn[getValarry(2,1)]++;
		        	   }
		        	   else{
		        		   swap(2,1, 3,1);
		        			cn[getValarry(2,1)]++;
		        	   }
	        	   }
	           	}
	       }
	}
	private void solveBox11() {
       
	       if(arry[2][2].equals(" ") ){
	    	   // swap box11 <-> box10
	           swap(2,2, 2,1);
	           heruetic[0] = chkHeu() + cn[getValarry(2,2)];
	           heruetic[4] = herue;
	           //set to normal state  11 <=> 10
	           normalState(2,2, 2,1);

	           // swap box11 <-> box7
	           swap(2,2, 1,2);
	           heruetic[1] = chkHeu() + cn[getValarry(2,2)];
	           heruetic[5] = herue;
	           //set to normal state  11 <=> 7
	           normalState(2,2, 1,2);

	           // swap box11 <-> box12
	           swap(2,2, 2,3);
	           heruetic[2] = chkHeu() + cn[getValarry(2,2)];
	           heruetic[6] = herue;
	           //set to normal state  11 <=> 12
	           normalState(2,2, 2,3);

	           // swap box11 <-> box15
	           swap(2,2, 3,2);
	           heruetic[3] = chkHeu() + cn[getValarry(2,2)];
	           heruetic[7] = herue;
	           //set to normal state  11 <=> 15
	           normalState(2,2, 3,2);
	           

	           if(heruetic[0] <= heruetic[1]){//xxxx big
	        	   if(heruetic[0] <= heruetic[2]){//xxx
	        		   if(heruetic[0] <= heruetic[3]){
	        			   swap(2,2, 2,1);
	        			   cn[getValarry(2,2)]++;
		        	   }
		        	   else{
		        		   swap(2,2, 3,2);
		        		   cn[getValarry(2,2)]++;
		        	   }

	        	   }
	        	   else{//xxx
	        		   if(heruetic[2] <= heruetic[3]){
		        		   swap(2,2, 2,3);
		        		   cn[getValarry(2,2)]++;
		        	   }
		        	   else{
		        		   swap(2,2, 3,2);
		        		   cn[getValarry(2,2)]++;
		        	   }
	        	   }
	           }else{//xxxx big
	        	   if(heruetic[1] <= heruetic[2]){
	        		   if(heruetic[1] <= heruetic[3]){
		        		   swap(2,2, 1,2);
		        		   cn[getValarry(2,2)]++;
		        	   }
		        	   else{
		        		   swap(2,2, 3,2);
		        		   cn[getValarry(2,2)]++;
		        	   }
	        	   }
	        	   else{
	        		   if(heruetic[2] <= heruetic[3]){
	        			   swap(2,2, 2,3);
	        			   cn[getValarry(2,2)]++;
		        	   }
		        	   else{
		        		   swap(2,2, 3,2);
		        		   cn[getValarry(2,2)]++;
		        	   }
	        	   }
	           	}
	       }
	}
	private void solveBox12() {
     
	       if(arry[2][3].equals(" ") ){
	    	// swap box12 <-> box11
	           swap(2,3, 2,2);
	           heruetic[0] = chkHeu() + cn[getValarry(2,3)];
	           heruetic[4] = herue;
	           //set to normal state  12 <=> 11
	           normalState(2,3, 2,2);

	           // swap box12 <-> box8
	           swap(2,3, 1,3);
	           heruetic[1] = chkHeu() + cn[getValarry(2,3)];
	           heruetic[5] = herue;
	           //set to normal state  12 <=> 8
	           normalState(2,3, 1,3);

	           // swap box12 <-> box16
	           swap(2,3, 3,3);
	           heruetic[2] = chkHeu() + cn[getValarry(2,3)];
	           heruetic[6] = herue;
	           //set to normal state  12 <=> 16
	           normalState(2,3, 3,3);
	           
	           if(heruetic[0] <= heruetic[1]){
	        	   if(heruetic[0] <= heruetic[2]){
	        		   swap(2,3, 2,2);
	        		   cn[getValarry(2,3)]++;
	        	   }
	        	   else{
	        		   swap(2,3, 3,3);
	        		   cn[getValarry(2,3)]++;
	        	   }
	           	}else{
	        	   if(heruetic[1] <= heruetic[2]){
	        		   swap(2,3, 1,3);
	        		   cn[getValarry(2,3)]++;
	        	   }
	        	   else{
	        		   swap(2,3, 3,3);
	        		   cn[getValarry(2,3)]++;
	        	   }
	           	}
	      }
	}
	private void solveBox13() {
      
	     if(arry[3][0].equals(" ") ){
	    	  // swap box13 <-> box9
	           swap(3,0, 2,0);
	           heruetic[0] = chkHeu() + cn[getValarry(3,0)];
	           heruetic[4] = herue;
	           //set to normal state  13 <=> 9
	           normalState(3,0, 2,0);

	           // swap box13 <-> box14
	           swap(3,0, 3,1);
	           heruetic[1] = chkHeu() + cn[getValarry(3,0)];
	           heruetic[5] = herue;
	           //set to normal state  13 <=> 9
	           normalState(3,0, 3,1);

	           if(heruetic[0] <= heruetic[1]){
		              // swap box13 <-> box9
		              swap(3,0, 2,0);
		              cn[getValarry(3,0)]++;
		           }else{
		               // swap box13 <-> box14
		              swap(3,0, 3,1);
		              cn[getValarry(3,0)]++;
		           }


	       }
	}
	private void solveBox14() {
      
	       if(arry[3][1].equals(" ") ){
	    	   // swap box14 <-> box13
	           swap(3,1, 3,0);
	           heruetic[0] = chkHeu() + cn[getValarry(3,1)];
	           heruetic[4] = herue;
	           //set to normal state  14 <=> 13
	           normalState(3,1, 3,0);

	           // swap box14 <-> box10
	           swap(3,1, 2,1);
	           heruetic[1] = chkHeu() + cn[getValarry(3,1)];
	           heruetic[5] = herue;
	           //set to normal state  14 <=> 10
	           normalState(3,1, 2,1);

	           // swap box14 <-> box15
	           swap(3,1, 3,2);
	           heruetic[2] = chkHeu() + cn[getValarry(3,1)];
	           heruetic[6] = herue;
	           //set to normal state  14 <=> 15
	           normalState(3,1, 3,2);

	           if(heruetic[0] <= heruetic[1]){
	        	   if(heruetic[0] <= heruetic[2]){
	        		   swap(3,1, 3,0);
	        			cn[getValarry(3,1)]++;
	        	   }
	        	   else{
	        		   swap(3,1, 3,2);
	        			cn[getValarry(3,1)]++;
	        	   }
	           	}else{
	        	   if(heruetic[1] <= heruetic[2]){
	        		   swap(3,1, 2,1);
	        			cn[getValarry(3,1)]++;
	        	   }
	        	   else{
	        		   swap(3,1, 3,2);
	        			cn[getValarry(3,1)]++;
	        	   }
	           	}
	       	}
	}
	private void solveBox15() {
       
	      if(arry[3][2].equals(" ") ){
	    	// swap box15 <-> box14
	           swap(3,2, 3,1);
	           heruetic[0] = chkHeu() + cn[getValarry(3,2)];
	           heruetic[4] = herue;
	           //set to normal state  15 <=> 14
	           normalState(3,2, 3,1);

	           // swap box15 <-> box11
	           swap(3,2, 2,2);
	           heruetic[1] = chkHeu() + cn[getValarry(3,2)];
	           heruetic[5] = herue;
	           //set to normal state  15 <=> 11
	           normalState(3,2, 2,2);

	         //set to normal state  15 <=> 16
	           swap(3,2, 3,3);
	           heruetic[2] = chkHeu() + cn[getValarry(3,2)];
	           heruetic[6] = herue;
	           //set to normal state  15 <=> 16
	           normalState(3,2, 3,3);

	           if(heruetic[0] <= heruetic[1]){
	        	   if(heruetic[0] <= heruetic[2]){
	        		   swap(3,2, 3,1);
	        		   cn[getValarry(3,2)]++;
	        	   }
	        	   else{
	        		   swap(3,2, 3,3);
	        		   cn[getValarry(3,2)]++;
	        	   }
	           	}else{
	        	   if(heruetic[1] <= heruetic[2]){
	        		   swap(3,2, 2,2);
	        		   cn[getValarry(3,2)]++;
	        	   }
	        	   else{
	        		   swap(3,2, 3,3);
	        		   cn[getValarry(3,2)]++;
	        	   }
	           	}
	}
	}
	
	private void solveBox16() {
       
	      if(arry[3][3].equals(" ")&&(herue != 0) ){
	    	// swap box16 <-> box15
	           swap(3,3, 3,2);
	           heruetic[0] = chkHeu() + cn[getValarry(3,3)];
	           heruetic[4] = herue;
	           //set to normal state  16 <=> 15
	           normalState(3,3, 3,2);

	           // swap box16 <-> box12
	           swap(3,3, 2,3);
	           heruetic[1] = chkHeu() + cn[getValarry(3,3)];
	           heruetic[4] = herue;
	           //set to normal state  16 <=> 12
	           normalState(3,3, 2,3);

	           if(heruetic[0] <= heruetic[1]){
		              // swap box16 <-> box15
		              swap(3,3, 3,2);
		              cn[getValarry(3,3)]++;
		           }else{
		               // swap box16 <-> box12
		              swap(3,3, 2,3);
		              cn[getValarry(3,3)]++;
		           }
	}
	}
	public int sumFn,herue;
	protected int chkHeu(){
		//int h[] = new int [16];	

		// --check btn0 h[0] heuristic function {box1}
		 if( arry[0][0].equals("1") ) h[0] = 0;
	else if( arry[0][0].equals("2") ) h[1] = 1;
	else if( arry[0][0].equals("3") ) h[2] = 2;
	else if( arry[0][0].equals("4") ) h[3] = 3;
	else if( arry[0][0].equals("5") ) h[4] = 1;
	else if( arry[0][0].equals("6") ) h[5] = 2;
	else if( arry[0][0].equals("7") ) h[6] = 3;
	else if( arry[0][0].equals("8") ) h[7] = 4;
	else if( arry[0][0].equals("9") ) h[8] = 2;
	else if( arry[0][0].equals("10") ) h[9] = 3;
	else if( arry[0][0].equals("11") ) h[10] = 4;
	else if( arry[0][0].equals("12") ) h[11] = 5;
	else if( arry[0][0].equals("13") ) h[12] = 3;
	else if( arry[0][0].equals("14") ) h[13] = 4;
	else if( arry[0][0].equals("15") ) h[14] = 5;
	else if( arry[0][0].equals(" ") )  h[15] = 0;

	// --check btn1 h[1] heuristic function {box2}
		 if( arry[0][1].equals("1") ) h[0] = 1;
	else if( arry[0][1].equals("2") ) h[1] = 0;
	else if( arry[0][1].equals("3") ) h[2] = 1;
	else if( arry[0][1].equals("4") ) h[3] = 2;
	else if( arry[0][1].equals("5") ) h[4] = 2;
	else if( arry[0][1].equals("6") ) h[5] = 1;
	else if( arry[0][1].equals("7") ) h[6] = 2;
	else if( arry[0][1].equals("8") ) h[7] = 3;
	else if( arry[0][1].equals("9") ) h[8] = 3;
	else if( arry[0][1].equals("10") ) h[9] = 2;
	else if( arry[0][1].equals("11") ) h[10] = 3;
	else if( arry[0][1].equals("12") ) h[11] = 4;
	else if( arry[0][1].equals("13") ) h[12] = 4;
	else if( arry[0][1].equals("14") ) h[13] = 3;
	else if( arry[0][1].equals("15") ) h[14] = 4;
	else if( arry[0][1].equals(" ") )  h[15] = 0;

	// --check btn2 h[2] heuristic function {box3}
		 if( arry[0][2].equals("1") ) h[0] = 2;
	else if( arry[0][2].equals("2") ) h[1] = 1;
	else if( arry[0][2].equals("3") ) h[2] = 0;
	else if( arry[0][2].equals("4") ) h[3] = 1;
	else if( arry[0][2].equals("5") ) h[4] = 3;
	else if( arry[0][2].equals("6") ) h[5] = 2;
	else if( arry[0][2].equals("7") ) h[6] = 1;
	else if( arry[0][2].equals("8") ) h[7] = 2;
	else if( arry[0][2].equals("9") ) h[8] = 4;
	else if( arry[0][2].equals("10") ) h[9] = 3;
	else if( arry[0][2].equals("11") ) h[10] = 2;
	else if( arry[0][2].equals("12") ) h[11] = 3;
	else if( arry[0][2].equals("13") ) h[12] = 5;
	else if( arry[0][2].equals("14") ) h[13] = 4;
	else if( arry[0][2].equals("15") ) h[14] = 3;
	else if( arry[0][2].equals(" ") )  h[15] = 0;

	// --check btn3 h[3] heuristic function {box4}
		 if( arry[0][3].equals("1") ) h[0] = 3;
	else if( arry[0][3].equals("2") ) h[1] = 2;
	else if( arry[0][3].equals("3") ) h[2] = 1;
	else if( arry[0][3].equals("4") ) h[3] = 0;
	else if( arry[0][3].equals("5") ) h[4] = 4;
	else if( arry[0][3].equals("6") ) h[5] = 3;
	else if( arry[0][3].equals("7") ) h[6] = 2;
	else if( arry[0][3].equals("8") ) h[7] = 1;
	else if( arry[0][3].equals("9") ) h[8] = 5;
	else if( arry[0][3].equals("10") ) h[9] = 4;
	else if( arry[0][3].equals("11") ) h[10] = 3;
	else if( arry[0][3].equals("12") ) h[11] = 2;
	else if( arry[0][3].equals("13") ) h[12] = 6;
	else if( arry[0][3].equals("14") ) h[13] = 5;
	else if( arry[0][3].equals("15") ) h[14] = 4;
	else if( arry[0][3].equals(" ") )  h[15] = 0;

	// --check btn4 h[4] heuristic function {box5}
		 if( arry[1][0].equals("1") ) h[0] = 1;
	else if( arry[1][0].equals("2") ) h[1] = 2;
	else if( arry[1][0].equals("3") ) h[2] = 3;
	else if( arry[1][0].equals("4") ) h[3] = 4;
	else if( arry[1][0].equals("5") ) h[4] = 0;
	else if( arry[1][0].equals("6") ) h[5] = 1;
	else if( arry[1][0].equals("7") ) h[6] = 2;
	else if( arry[1][0].equals("8") ) h[7] = 3;
	else if( arry[1][0].equals("9") ) h[8] = 1;
	else if( arry[1][0].equals("10") ) h[9] = 2;
	else if( arry[1][0].equals("11") ) h[10] = 3;
	else if( arry[1][0].equals("12") ) h[11] = 4;
	else if( arry[1][0].equals("13") ) h[12] = 2;
	else if( arry[1][0].equals("14") ) h[13] = 3;
	else if( arry[1][0].equals("15") ) h[14] = 4;
	else if( arry[1][0].equals(" ")  ) h[15] = 0;

	// --check btn5 h[5] heuristic function {box6}
		 if( arry[1][1].equals("1") ) h[0] = 2;
	else if( arry[1][1].equals("2") ) h[1] = 1;
	else if( arry[1][1].equals("3") ) h[2] = 2;
	else if( arry[1][1].equals("4") ) h[3] = 3;
	else if( arry[1][1].equals("5") ) h[4] = 1;
	else if( arry[1][1].equals("6") ) h[5] = 0;
	else if( arry[1][1].equals("7") ) h[6] = 1;
	else if( arry[1][1].equals("8") ) h[7] = 2;
	else if( arry[1][1].equals("9") ) h[8] = 2;
	else if( arry[1][1].equals("10") ) h[9] = 1;
	else if( arry[1][1].equals("11") ) h[10] = 2;
	else if( arry[1][1].equals("12") ) h[11] = 3;
	else if( arry[1][1].equals("13") ) h[12] = 3;
	else if( arry[1][1].equals("14") ) h[13] = 2;
	else if( arry[1][1].equals("15") ) h[14] = 3;
	else if( arry[1][1].equals(" ") )  h[15] = 0;

	// --check btn6 h[6] heuristic function {box7}
		 if( arry[1][2].equals("1") ) h[0] = 3;
	else if( arry[1][2].equals("2") ) h[1] = 2;
	else if( arry[1][2].equals("3") ) h[2] = 1;
	else if( arry[1][2].equals("4") ) h[3] = 2;
	else if( arry[1][2].equals("5") ) h[4] = 2;
	else if( arry[1][2].equals("6") ) h[5] = 1;
	else if( arry[1][2].equals("7") ) h[6] = 0;
	else if( arry[1][2].equals("8") ) h[7] = 1;
	else if( arry[1][2].equals("9") ) h[8] = 3;
	else if( arry[1][2].equals("10") ) h[9] = 2;
	else if( arry[1][2].equals("11") ) h[10] = 1;
	else if( arry[1][2].equals("12") ) h[11] = 2;
	else if( arry[1][2].equals("13") ) h[12] = 4;
	else if( arry[1][2].equals("14") ) h[13] = 3;
	else if( arry[1][2].equals("15") ) h[14] = 2;
	else if( arry[1][2].equals(" ") )  h[15] = 0;

	// --check btn7 h[7] heuristic function {box8}
		 if( arry[1][3].equals("1") ) h[0] = 4;
	else if( arry[1][3].equals("2") ) h[1] = 3;
	else if( arry[1][3].equals("3") ) h[2] = 2;
	else if( arry[1][3].equals("4") ) h[3] = 1;
	else if( arry[1][3].equals("5") ) h[4] = 3;
	else if( arry[1][3].equals("6") ) h[5] = 2;
	else if( arry[1][3].equals("7") ) h[6] = 1;
	else if( arry[1][3].equals("8") ) h[7] = 0;
	else if( arry[1][3].equals("9") ) h[8] = 4;
	else if( arry[1][3].equals("10") ) h[9] = 3;
	else if( arry[1][3].equals("11") ) h[10] = 2;
	else if( arry[1][3].equals("12") ) h[11] = 1;
	else if( arry[1][3].equals("13") ) h[12] = 5;
	else if( arry[1][3].equals("14") ) h[13] = 4;
	else if( arry[1][3].equals("15") ) h[14] = 3;
	else if( arry[1][3].equals(" ") )  h[15] = 0;

	// --check btn8 h[8] heuristic function {box9}
		 if( arry[2][0].equals("1") ) h[0] = 2;
	else if( arry[2][0].equals("2") ) h[1] = 3;
	else if( arry[2][0].equals("3") ) h[2] = 4;
	else if( arry[2][0].equals("4") ) h[3] = 5;
	else if( arry[2][0].equals("5") ) h[4] = 1;
	else if( arry[2][0].equals("6") ) h[5] = 2;
	else if( arry[2][0].equals("7") ) h[6] = 3;
	else if( arry[2][0].equals("8") ) h[7] = 4;
	else if( arry[2][0].equals("9") ) h[8] = 0;
	else if( arry[2][0].equals("10") ) h[9] = 1;
	else if( arry[2][0].equals("11") ) h[10] = 2;
	else if( arry[2][0].equals("12") ) h[11] = 3;
	else if( arry[2][0].equals("13") ) h[12] = 1;
	else if( arry[2][0].equals("14") ) h[13] = 2;
	else if( arry[2][0].equals("15") ) h[14] = 3;
	else if( arry[2][0].equals(" ") )  h[15] = 0;


	// --check btn9 h[9] heuristic function {box10}
		 if( arry[2][1].equals("1") ) h[0] = 3;
	else if( arry[2][1].equals("2") ) h[1] = 2;
	else if( arry[2][1].equals("3") ) h[2] = 3;
	else if( arry[2][1].equals("4") ) h[3] = 4;
	else if( arry[2][1].equals("5") ) h[4] = 2;
	else if( arry[2][1].equals("6") ) h[5] = 1;
	else if( arry[2][1].equals("7") ) h[6] = 2;
	else if( arry[2][1].equals("8") ) h[7] = 3;
	else if( arry[2][1].equals("9") ) h[8] = 1;
	else if( arry[2][1].equals("10") ) h[9] = 0;
	else if( arry[2][1].equals("11") ) h[10] = 1;
	else if( arry[2][1].equals("12") ) h[11] = 2;
	else if( arry[2][1].equals("13") ) h[12] = 2;
	else if( arry[2][1].equals("14") ) h[13] = 1;
	else if( arry[2][1].equals("15") ) h[14] = 2;
	else if( arry[2][1].equals(" ") )  h[15] = 0;

		// --check btn10 h[10] heuristic function {box11}
		 if( arry[2][2].equals("1") ) h[0] = 4;
	else if( arry[2][2].equals("2") ) h[1] = 3;
	else if( arry[2][2].equals("3") ) h[2] = 2;
	else if( arry[2][2].equals("4") ) h[3] = 3;
	else if( arry[2][2].equals("5") ) h[4] = 3;
	else if( arry[2][2].equals("6") ) h[5] = 2;
	else if( arry[2][2].equals("7") ) h[6] = 1;
	else if( arry[2][2].equals("8") ) h[7] = 2;
	else if( arry[2][2].equals("9") ) h[8] = 2;
	else if( arry[2][2].equals("10") ) h[9] = 1;
	else if( arry[2][2].equals("11") ) h[10] = 0;
	else if( arry[2][2].equals("12") ) h[11] = 1;
	else if( arry[2][2].equals("13") ) h[12] = 3;
	else if( arry[2][2].equals("14") ) h[13] = 2;
	else if( arry[2][2].equals("15") ) h[14] = 1;
	else if( arry[2][2].equals(" ") )  h[15] = 0;

		// --check btn11 h[11] heuristic function {box12}
		 if( arry[2][3].equals("1") ) h[0] = 5;
	else if( arry[2][3].equals("2") ) h[1] = 4;
	else if( arry[2][3].equals("3") ) h[2] = 3;
	else if( arry[2][3].equals("4") ) h[3] = 2;
	else if( arry[2][3].equals("5") ) h[4] = 4;
	else if( arry[2][3].equals("6") ) h[5] = 3;
	else if( arry[2][3].equals("7") ) h[6] = 2;
	else if( arry[2][3].equals("8") ) h[7] = 1;
	else if( arry[2][3].equals("9") ) h[8] = 3;
	else if( arry[2][3].equals("10") ) h[9] = 2;
	else if( arry[2][3].equals("11") ) h[10] = 1;
	else if( arry[2][3].equals("12") ) h[11] = 0;
	else if( arry[2][3].equals("13") ) h[12] = 4;
	else if( arry[2][3].equals("14") ) h[13] = 3;
	else if( arry[2][3].equals("15") ) h[14] = 2;
	else if( arry[2][3].equals(" ") )  h[15] = 0;

		// --check btn12 h[12] heuristic function {box13}
		 if( arry[3][0].equals("1") ) h[0] = 3;
	else if( arry[3][0].equals("2") ) h[1] = 4;
	else if( arry[3][0].equals("3") ) h[2] = 5;
	else if( arry[3][0].equals("4") ) h[3] = 6;
	else if( arry[3][0].equals("5") ) h[4] = 2;
	else if( arry[3][0].equals("6") ) h[5] = 3;
	else if( arry[3][0].equals("7") ) h[6] = 4;
	else if( arry[3][0].equals("8") ) h[7] = 5;
	else if( arry[3][0].equals("9") ) h[8] = 1;
	else if( arry[3][0].equals("10") ) h[9] = 2;
	else if( arry[3][0].equals("11") ) h[10] = 3;
	else if( arry[3][0].equals("12") ) h[11] = 4;
	else if( arry[3][0].equals("13") ) h[12] = 0;
	else if( arry[3][0].equals("14") ) h[13] = 1;
	else if( arry[3][0].equals("15") ) h[14] = 2;
	else if( arry[3][0].equals(" ") )  h[15] = 0;

		// --check btn13 h[13] heuristic function {box14}
		 if( arry[3][1].equals("1") ) h[0] = 4;
	else if( arry[3][1].equals("2") ) h[1] = 3;
	else if( arry[3][1].equals("3") ) h[2] = 4;
	else if( arry[3][1].equals("4") ) h[3] = 5;
	else if( arry[3][1].equals("5") ) h[4] = 3;
	else if( arry[3][1].equals("6") ) h[5] = 2;
	else if( arry[3][1].equals("7") ) h[6] = 3;
	else if( arry[3][1].equals("8") ) h[7] = 4;
	else if( arry[3][1].equals("9") ) h[8] = 2;
	else if( arry[3][1].equals("10") ) h[9] = 1;
	else if( arry[3][1].equals("11") ) h[10] = 2;
	else if( arry[3][1].equals("12") ) h[11] = 3;
	else if( arry[3][1].equals("13") ) h[12] = 1;
	else if( arry[3][1].equals("14") ) h[13] = 0;
	else if( arry[3][1].equals("15") ) h[14] = 1;
	else if( arry[3][1].equals(" ") )  h[15] = 0;

		// --check btn14 h[14] heuristic function {box15}
		 if( arry[3][2].equals("1") ) h[0] = 5;
	else if( arry[3][2].equals("2") ) h[1] = 4;
	else if( arry[3][2].equals("3") ) h[2] = 3;
	else if( arry[3][2].equals("4") ) h[3] = 4;
	else if( arry[3][2].equals("5") ) h[4] = 4;
	else if( arry[3][2].equals("6") ) h[5] = 3;
	else if( arry[3][2].equals("7") ) h[6] = 2;
	else if( arry[3][2].equals("8") ) h[7] = 3;
	else if( arry[3][2].equals("9") ) h[8] = 3;
	else if( arry[3][2].equals("10")) h[9] = 2;
	else if( arry[3][2].equals("11") ) h[10] = 1;
	else if( arry[3][2].equals("12") ) h[11] = 2;
	else if( arry[3][2].equals("13") ) h[12] = 2;
	else if( arry[3][2].equals("14") ) h[13] = 1;
	else if( arry[3][2].equals("15") ) h[14] = 0;
	else if( arry[3][2].equals(" ") )  h[15] = 0;

		// --check btn15 h[15] heuristic function {box16 is space}
		 if( arry[3][3].equals("1") ) h[0] = 6;
	else if( arry[3][3].equals("2") ) h[1] = 5;
	else if( arry[3][3].equals("3") ) h[2] = 4;
	else if( arry[3][3].equals("4") ) h[3] = 3;
	else if( arry[3][3].equals("5") ) h[4] = 5;
	else if( arry[3][3].equals("6") ) h[5] = 4;
	else if( arry[3][3].equals("7") ) h[6] = 3;
	else if( arry[3][3].equals("8") ) h[7] = 2;
	else if( arry[3][3].equals("9") ) h[8] = 4;
	else if( arry[3][3].equals("10")) h[9] = 3;
	else if( arry[3][3].equals("11") ) h[10] = 2;
	else if( arry[3][3].equals("12") ) h[11] = 1;
	else if( arry[3][3].equals("13") ) h[12] = 3;
	else if( arry[3][3].equals("14") ) h[13] = 2;
	else if( arry[3][3].equals("15") ) h[14] = 1;
	else if( arry[3][3].equals(" ") )  h[15] = 0;

		this.herue = h[0] + h[1] + h[2] + h[3] + h[4] + h[5] + h[6] + h[7] + h[8] + h[9] + h[10] + h[11] + h[12] + h[13] + h[14]+ h[15];
		sumFn = cAstar+herue;
		
		return sumFn;
		
    }
   
}
